package logic

import (
	"context"
	"gorm.io/gorm"
	"taobao-merchandis/model"

	"taobao-merchandis/taobaorpc/internal/svc"
	"taobao-merchandis/taobaorpc/taobaorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpDataLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpDataLogic {
	return &UpDataLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpDataLogic) UpData(in *taobaorpc.UpDataRequest) (*taobaorpc.UpDataResponse, error) {
	// todo: add your logic here and delete this line
	goods := model.Goods{
		Model:  gorm.Model{ID: uint(in.GoodsId)},
		Title:  in.Title,
		Price:  float64(in.Price),
		Image:  in.Image,
		UserId: int(in.UserId),
	}
	model.DB.Updates(&goods)
	return &taobaorpc.UpDataResponse{
		GoodsId: int64(goods.ID),
	}, nil
}
